package cn.iocoder.yudao.module.moa.service.expensecategory;

import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.moa.controller.admin.expensecategory.vo.*;
import cn.iocoder.yudao.module.moa.dal.dataobject.expensecategory.ExpenseCategoryDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.moa.dal.mysql.expensecategory.ExpenseCategoryMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;


/**
 * 费用类型 Service 实现类
 *
 * @author 管理员
 */
@Service
@Validated
public class ExpenseCategoryServiceImpl implements ExpenseCategoryService {

    @Resource
    private ExpenseCategoryMapper expenseCategoryMapper;

    @Override
    public String createExpenseCategory(ExpenseCategorySaveReqVO createReqVO) {
        // 插入
        ExpenseCategoryDO expenseCategory = BeanUtils.toBean(createReqVO, ExpenseCategoryDO.class);
        expenseCategoryMapper.insert(expenseCategory);
        // 返回
        return expenseCategory.getId();
    }

    @Override
    public void updateExpenseCategory(ExpenseCategorySaveReqVO updateReqVO) {
        // 校验存在
        validateExpenseCategoryExists(updateReqVO.getId());
        // 更新
        ExpenseCategoryDO updateObj = BeanUtils.toBean(updateReqVO, ExpenseCategoryDO.class);
        expenseCategoryMapper.updateById(updateObj);
    }

    @Override
    public void deleteExpenseCategory(String id) {
        // 校验存在
        validateExpenseCategoryExists(id);
        // 删除
        expenseCategoryMapper.deleteById(id);
    }

    private void validateExpenseCategoryExists(String id) {
        if (expenseCategoryMapper.selectById(id) == null) {

        }
    }

    @Override
    public ExpenseCategoryDO getExpenseCategory(String id) {
        return expenseCategoryMapper.selectById(id);
    }

    @Override
    public PageResult<ExpenseCategoryDO> getExpenseCategoryPage(ExpenseCategoryPageReqVO pageReqVO) {
        return expenseCategoryMapper.selectPage(pageReqVO);
    }

}
